<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组扩展求最大值和求和方法</title>
</head>

<body>
  <script>
    // ============================== 数组扩展求最大值和求和方法 ==============================
    // 1. 数组扩展求最大值/最小值
    // 2. 数组扩展求和方法

    const arr1 = [1, 2, 3]
    const arr2 = [10, 20, 30]
    const arr3 = [66, 28, 36]

    // 数组扩展求最大值
    Array.prototype.max=function () {
      return Math.max(...this)
    }


    console.log(arr1.max())
    console.log(arr2.max())
    console.log(arr3.max())
    // 数组扩展求最小值
    Array.prototype.min=function () {
      return Math.min(...this)
    }
    

    console.log(arr1.min())
    console.log(arr2.min())
    console.log(arr3.min())

    // 数组扩展求求和
    Array.prototype.sum=function(){
      return this.reduce((prev,item) => prev+item,0)
    }

    // 从而可以让数组调用 max min sum方法
    
    console.log(arr1.sum())
    console.log(arr2.sum())
    console.log(arr3.sum())

  </script>
</body>

</html>